// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.commands.serverCommands;

import java.sql.SQLException;
import zombie.characters.IsoPlayer;
import zombie.commands.CommandBase;
import zombie.commands.CommandHelp;
import zombie.commands.CommandName;
import zombie.commands.RequiredRight;
import zombie.core.raknet.UdpConnection;
import zombie.iso.areas.SafeHouse;
import zombie.network.GameServer;

@CommandName(
    name = "releasesafehouse"
)
@CommandHelp(
    helpText = "UI_ServerOptionDesc_SafeHouse"
)
@RequiredRight(
    requiredRights = 63
)
public class ReleaseSafehouseCommand extends CommandBase {
    public ReleaseSafehouseCommand(String username, String userAccessLevel, String command, UdpConnection connection) {
        super(username, userAccessLevel, command, connection);
    }

    @Override
    protected String Command() throws SQLException {
        if (this.isCommandComeFromServerConsole()) {
            return getCommandName(this.getClass()) + " can be executed only from the game";
        } else {
            String string = this.getExecutorUsername();
            IsoPlayer isoPlayer = GameServer.getPlayerByUserNameForCommand(string);
            SafeHouse safeHouse = SafeHouse.hasSafehouse(string);
            if (safeHouse != null) {
                if (!safeHouse.isOwner(isoPlayer)) {
                    return "Only owner can release safehouse";
                } else {
                    safeHouse.removeSafeHouse(isoPlayer);
                    return "Your safehouse was released";
                }
            } else {
                return "You have no safehouse";
            }
        }
    }
}
